/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bookshop.dao;
import com.bookshop.entity.Category;
import com.bookshop.exception.EBookshopException;
import javax.ejb.Singleton;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Caroline
 */
@Singleton(mappedName = "com.bookshop.dao.category")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DaoCategoryImpl implements IDaoCategoryLocal, IDaoCategoryRemote {
    
    @PersistenceContext
    private EntityManager em;

    @Override
    public Category getCategoryById(int categoryId) {
        try {
            return (Category) em.createNamedQuery("Category.findById").setParameter("id", categoryId).getSingleResult();
        } catch(Throwable th) {
            throw new EBookshopException(th.getMessage(), th);
        }
    }
    
}
